#ifndef ONLINEMEETING_H
#define ONLINEMEETING_H

#include <QWidget>
#include <QUdpSocket>
#include "../MeetingServer/messagepackage.h"
#include "sockethandler.h"
#include "camerahandler.h"
#include "videosender.h"
#include "videorecever.h"
#include "audiohandler.h"
#include <QCloseEvent>
#include <QThread>
#include <QTimer>

namespace Ui {
class OnlineMeeting;
}

class OnlineMeeting : public QWidget
{
    Q_OBJECT

public:
    explicit OnlineMeeting(QString meetingName, QString userName, QString ip, quint16 port, bool isCreateor = false, QWidget *parent = nullptr);
    ~OnlineMeeting();
protected:
    virtual void closeEvent(QCloseEvent *event) override;
private slots:
    void on_btn_inviteUser_clicked();
    void on_btn_finish_clicked();


    void on_btn_camera_clicked();
    void onCameraChanged(QCamera::State state);

    void videoSet(QImage image);

    void onGetFps(int value);
    void onStateChanged(QAudio::State state);

    void onTimeout();

public slots:
    void onUpdateMeeting(messagePackage pack);

    void on_videoUpdate(QImage image);
    void on_horizontalSlider_valueChanged(int value);

private:
    Ui::OnlineMeeting *ui;
    QString meetingName;
    QString userName;
    QString ip;
    quint16 port;
    bool isCreator;
    QThread *socketThread = nullptr;
    QThread *cameraThread = nullptr;

    CameraHandler *camera = nullptr;
    VideoSender *sender = nullptr;

    VideoRecever *recever = nullptr;

    AudioHandler *audio = nullptr;

    QTimer *timer;
    int fps = 0;

signals:
    void closeMeeting();
    void btnChang();
};

#endif // ONLINEMEETING_H
